﻿
Namespace Blog

    Public Class CommentUtils

        Public Shared Function GetCommentById(ByVal intCommentId As Integer) As Comment

            Dim objComment As BlogSpark.Blog.Comment
            Dim dt As DataTable = BlogSpark.DataProvider.SPs.GetCommentsByCommentId(BlogSpark.DataProvider.Data.ConnectionType, intCommentId).Tables(0)

            If dt.Rows.Count > 0 Then
                objComment = New BlogSpark.Blog.Comment
                objComment.Fill(dt.Rows(0))
                Return objComment
            Else
                Return Nothing
            End If

        End Function

        Public Shared Function GetCommentsByPostId(ByVal intPostId As Integer) As Comment()

            Dim dt As DataTable = BlogSpark.DataProvider.SPs.GetCommentsByPostId(BlogSpark.DataProvider.Data.ConnectionType, intPostId).Tables(0)
            Dim i As Integer = 0
            Dim objComments(dt.Rows.Count - 1) As Comment

            For Each dr As DataRow In dt.Select

                objComments(i) = New BlogSpark.Blog.Comment
                objComments(i).Fill(dr)

                i += 1

            Next

            Return objComments

        End Function

    End Class

End Namespace

